package main

import "fmt"

func balancedStringSplit(s string) int {
	result := 0
	if len(s) == 0 {
		return result
	}
	cache := s[0:1]
	for i := 1; i < len(s); i++ {
		if len(cache) == 0 {
			cache = s[i : i+1]
			continue
		}
		if s[i] != cache[len(cache)-1] {
			cache = cache[0 : len(cache)-1]
		} else {
			cache += s[i : i+1]
		}
		if len(cache) == 0 {
			result += 1
			//i+=1
			//cache = s[i:i+1]
			//continue
		}
	}
	return result
}

func main() {
	s := "RLRRLLRLRL"
	r := balancedStringSplit(s)
	fmt.Println(r)
}
